package com.example.pattern.interpreter;

/**
 * 应用上下文
 *
 * @author FM_南风
 * @date 2024/7/7
 */
public class InterpreterContext {
	private Expression defineGrammar(String[] rules) {
 		Expression rule1 = new TerminalExpression(rules[0]);
  		Expression rule2 = new TerminalExpression(rules[1]);
  		return new OrExpression(rule1, rule2);
 	}

 	public void interpret(String context, String[] rules) {
  		Expression define = defineGrammar(rules);
  		System.out.println(context + " is " + define.interpret(context));
 	}
}